package cn.yujiago.portal.controller;

import cn.yujiago.portal.pojo.BackAdminResult;
import cn.yujiago.portal.pojo.Image;
import cn.yujiago.portal.utils.HttpClientUtil;
import cn.yujiago.portal.utils.JsonUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ImageController {

    @GetMapping("/image/listpage")
    public String getAllImageByPojo( Model model){

//        String json = HttpClientUtil.doGet("http://www.backadmin.yujiago.cn/image/list");
        String json = HttpClientUtil.doGet("http://localhost:80/image/list");

        if(!StringUtils.isEmpty(json)){
            BackAdminResult result = JsonUtils.jsonToPojo(json, BackAdminResult.class);
            List<Image> images = (List<Image>) result.getData();
            model.addAttribute("images", images);
        }

        return "index";
    }

}
